// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: qjs_style_sheet_list.cpp
// Description: Bindings for StyleSheetList
//      Author: Ziming Li
//     Created: 2022-04-11
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

#include "./qjs_bindings.h"

#include "blinkit/blink/renderer/bindings/core/qjs/qjs.h"
#include "blinkit/blink/renderer/bindings/core/qjs/qjs_c_function_list_entries.h"
#include "blinkit/blink/renderer/core/css/style_sheet_list.h"

/**
 * https://developer.mozilla.org/en-US/docs/Web/API/StyleSheetList
 */

namespace BlinKit {
namespace qjs {

static JSValue GetLength(JSContext *ctx, JSValueConst thisVal)
{
    StyleSheetList *styleSheetList = ScriptWrappable::Cast<StyleSheetList>(thisVal);
    return JS_NewUint32(ctx, styleSheetList->length());
}

static JSValue Item(JSContext *ctx, JSValueConst thisVal, int argc, JSValueConst *argv)
{
    StyleSheetList *styleSheetList = ScriptWrappable::Cast<StyleSheetList>(thisVal);
    ASSERT(false); // BKTODO:
    return JS_UNDEFINED;
}

JSValue CreateStyleSheetListPrototype(JSContext *ctx)
{
    static const JSCFunctionListEntry Funcs[] = {
        CFunctionEntry(Strings::Item, 1, Item),
        CGetSetEntry(Strings::Length, GetLength, nullptr)
    };

    JSValue ret = JS_NewObject(ctx);
    JS_SetPropertyFunctionList(ctx, ret, Funcs, std::size(Funcs));
    return ret;
}

} // namespace qjs
} // namespace BlinKit
